<?php
class My_Plugin_ViewSetup extends Zend_Controller_Plugin_Abstract
{
	public function preDispatch(Zend_Controller_Request_Abstract $request)
	{
		$module = $request->getModuleName(); 

		$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
        $view = $viewRenderer->view;
        $view->baseURL = Zend_Controller_Front::getInstance()->getBaseUrl();
        
        if($module == "admin")
        {
			$action = $request->getActionName();
			$auth = Zend_Auth::getInstance();
			if (!$auth->hasIdentity() && $action != "login") {
				$url = $view->url( array('controller'=>'user','module'=>'admin','action'=>'login'),'default', true);
	    		header("location:$url");
	    		exit(); 
			}
        }
       
        My_Validate::quoteRequest();
        
	}
	
}